package initialize

import (
	"fmt"
	"gitee.com/youbeiwuhuan/gin-practice/gin-simple-zap/global"
	"gitee.com/youbeiwuhuan/gin-practice/gin-simple-zap/global/config"
	"gitee.com/youbeiwuhuan/gin-practice/gin-simple-zap/tools/configs"
	"gitee.com/youbeiwuhuan/gin-practice/gin-simple-zap/tools/zaps"
	"sync"
)

func InitAll() {
	LoandConfig()
	initZap()
}

var (
	loandConfigOnce sync.Once
)

func LoandConfig() {
	loandConfigOnce.Do(func() {
		loandConfig()
	})
}
func loandConfig() {

	global.ViperCfg = configs.Load()
	vp := global.ViperCfg
	if err := vp.Unmarshal(&config.TotalConfig); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(config.TotalConfig)
	}

}
func initZap() {
	global.ZapLog = zaps.CreateZapFactory(config.TotalConfig.Zap, zaps.ZapLogHandler)

}
